package pe.org.cnl.congreso.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import pe.org.cnl.congreso.model.Usuario;


@Controller
@Scope("session")
public class LoginController {
	
	private static final Logger logger = Logger.getLogger(LoginController.class);
	
	@RequestMapping("login.htm")
	public String login(  ){
		logger.debug("llendo al login");	
		return "login";
	}
	
	@RequestMapping(value = "index.htm")
	public String index() {
		return "index";
	}
	
	@RequestMapping("inicio.htm")
	public String inicio(HttpServletRequest request,HttpServletResponse response, ModelMap model){
		logger.debug("llendo al inicio");
		try {
			response.setContentType("text/html;charset=ISO-8859-1");
	        request.setCharacterEncoding("UTF8");
			request.getSession().setAttribute("usrLogin", Usuario.getUsuarioBean() );
		} catch (Exception e) {
			e.printStackTrace();
			model.put("msgError", e.getMessage());
		}
		logger.debug("return al inicio");
		return "index";
	}
	
}
